/**
 * 2009/12/04
 */
package com.googlecode.felicalib.sample.polling;

import java.util.Map;
import java.util.WeakHashMap;

/**
 * @author o.tanaka
 */
public class Polling {

    private String idm;
    private String pmm;
    private Map<String, CardInfo> data;

    /**
     * @return data
     */
    public final Map<String, CardInfo> getData() {
        return this.data;
    }

    /**
     * @param serviceCode
     *            serviceCode
     * @param addr
     *            addr
     * @return data
     */
    public final String getData(
            final int serviceCode, final byte addr) {
        final String key =
            String.valueOf(serviceCode) + String.valueOf(addr);
        if ((this.data != null) && (this.data.get(key) != null)) {
            return this.data.get(key).getValue();
        }
        return null;
    }

    /**
     * @return idm
     */
    public final String getIDm() {
        return this.idm;
    }

    /**
     * @return pmm
     */
    public final String getPMm() {
        return this.pmm;
    }

    /**
     * @param aData data class
     */
    public final void putData(final CardInfo aData) {
        if (this.data != null) {
            if (this.data.get(aData.getKey()) != null) {
                this.data.remove(aData.getKey());
            }
            this.data.put(aData.getKey(), aData);
        } else {
            this.data = new WeakHashMap<String, CardInfo>();
            this.data.put(aData.getKey(), aData);
        }
    }

    /**
     * @param aData
     *            the data to set
     */
    public final void setData(final Map<String, CardInfo> aData) {
        this.data = aData;
    }

    /**
     * @param aIDm
     *            IDm
     */
    public void setIDm(final String aIDm) {
        this.idm = aIDm;
    }

    /**
     * @param aPmm
     *            the pmm to set
     */
    public final void setPMm(final String aPmm) {
        this.pmm = aPmm;
    }

}
